package com.myproject.mall.common.result;

import com.myproject.mall.common.constants.GlobalCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class HttpResult<T> {
    private GlobalCode code;
    private Integer num;
    private String message;
    private T data;

    public static <T> HttpResult<T> success() {
        return new HttpResult<>(GlobalCode.SUCCESS, GlobalCode.SUCCESS.getCode(), "success", null);
    }

    public static <T> HttpResult<T> success(T data) {
        return new HttpResult<>(GlobalCode.SUCCESS, GlobalCode.SUCCESS.getCode(), "success", data);
    }

    public static <T> HttpResult<T> success(T data, String message) {
        return new HttpResult<>(GlobalCode.SUCCESS, GlobalCode.SUCCESS.getCode(), message, data);
    }

    public static <T> HttpResult<T> fail(GlobalCode code) {
        return new HttpResult<>(code, code.getCode(), code.getMessage(), null);
    }

    public static <T> HttpResult<T> fail(GlobalCode code, String message) {
        return new HttpResult<>(code, code.getCode(), message, null);
    }

    public static <T> HttpResult<T> fail(String message) {
        return new HttpResult<>(GlobalCode.FAIL, GlobalCode.FAIL.getCode(), message, null);
    }
}
